import logging

class Log:
    def __init__(self, name: str, mode: str = "plantuml") -> None:
        if (mode is None) or (mode != "plantuml" and mode != "log"):    
            raise ValueError("mode must be 'plantuml' or 'log'")
        self.mode = mode
        self.logger = self.get_logger(name)
        if self.mode == "plantuml":
            self.logger.info("@startuml model")
    
    # def __del__(self):
    #     if self.mode == "plantuml":
    #         self.logger.info("@enduml")

    def get_logger(self, name: str) -> logging.Logger:
        """
        Returns a logger that logs to a file and the console.
        """
        logger = logging.getLogger(name)
        logger.setLevel(logging.INFO)

        # file_handler = logging.FileHandler(f"./logs/{name}")
        file_handler = logging.FileHandler(f"../logs/{name}")
        file_handler.setLevel(logging.INFO)
        formatter = logging.Formatter("%(message)s")
        file_handler.setFormatter(formatter)

        console_handler = logging.StreamHandler()
        console_handler.setLevel(logging.INFO)

        logger.addHandler(file_handler)
        logger.addHandler(console_handler)

        return logger

    
    def info(self, msg: str) -> None:
        self.logger.info(msg)
